from typing import List


class Solution:
    def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
        l = r = 0
        n = len(gas)
        sums = 0
        while l < n:
            sums += gas[r % n] - cost[r % n]
            if sums < 0:
                l = r + 1
                r = r + 1
                sums = 0
                continue
            if r - l + 1 == n:
                return l
            r += 1
        return -1

if __name__ == '__main__':
    s = Solution()
    r = s.canCompleteCircuit([3,3,4],[3,4,4])
    print(r)